home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ld / ld_front.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-25  |  2.7 KB  |  115 lines

  1. /* 
  2.  * ld_front.c --
  3.  *
  4.  *    Front end for loader.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/cmds/ld/RCS/ld_front.c,v 1.2 90/08/06 21:07:08 rab Exp Locker: rab $";
  18. #endif /* not lint */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <sys/param.h>
  24. #include <assert.h>
  25. #ifndef __STDC__
  26. #define const
  27. #endif
  28.  
  29. #ifndef EXIT_FAILURE
  30. #define EXIT_FAILURE    1
  31. #endif
  32.  
  33. #ifdef sun3
  34. static const char *hostMachine = "sun3";
  35. #else
  36. #ifdef sun4
  37. static const char *hostMachine = "sun4";
  38. #else
  39. #ifdef ds3100
  40. static const char *hostMachine = "ds3100";
  41. #else
  42. #ifdef symm
  43. static const char *hostMachine = "symm";
  44. #else
  45. NO DEFAULT TARGET MACHINE TYPE DEFINED
  46. #endif
  47. #endif
  48. #endif
  49. #endif
  50.  
  51. /*
  52.  *----------------------------------------------------------------------
  53.  *
  54.  * main --
  55.  *      Search through the command line arguments looking for an argument
  56.  *      of the form -mfoo, where `foo' is a machine type.  If found, delete
  57.  *      it from the list of arguments, and use it to determine which
  58.  *      backend to exec.  If there is no -m then default to the type
  59.  *      of the host machine.
  60.  *
  61.  * Results:
  62.  *    None.
  63.  *
  64.  * Side effects:
  65.  *    Execs machine dependent loader backend.
  66.  *
  67.  *----------------------------------------------------------------------
  68.  */
  69.  
  70. void
  71. main(argc, argv)
  72.     int argc;
  73.     char **argv;
  74. {
  75.     extern int errno;
  76.     int i;
  77.     int j;
  78.     const char *targetMachine;
  79.     char path[MAXPATHLEN];
  80.  
  81.     targetMachine = hostMachine;
  82.     for (i = 1; i < argc; ++i) {
  83.     if (argv[i][0] == '-' && argv[i][1] == 'm') {
  84.         if (argv[i][2] == '\0') {
  85.         targetMachine = argv[i + 1];
  86.         if (targetMachine == NULL) {
  87.             (void) fprintf(stderr, "No target machine specified\n");
  88.             exit(EXIT_FAILURE);
  89.         }
  90.         for (j = i; j < argc - 1; ++j) {
  91.             argv[j] = argv[j + 2];
  92.         }
  93.         argc -= 2;
  94.         assert(argv[argc] == NULL);
  95.         } else {
  96.         targetMachine = argv[i] + 2;
  97.         for (j = i; j < argc; ++j) {
  98.             argv[j] = argv[j + 1];
  99.         }
  100.         --argc;
  101.         assert(argv[argc] == NULL);
  102.         }
  103.         break;
  104.     }
  105.     }
  106.     assert(argc >= 1);
  107.     (void) sprintf(path,
  108.     "/sprite/lib/gcc/%s.md/ld.%s", hostMachine, targetMachine);
  109.     argv[0] = path;
  110.     (void) execv(path, argv);
  111.     (void) fprintf(stderr, "Can't exec ``%s'': %s\n", path, strerror(errno));
  112.     exit(EXIT_FAILURE);
  113. }
  114.  
  115.